<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( "../global/initialize.php");

aos_header( 'Translations' );
?>
					<table>
						<tr><th colspan="5"><?php transprint( 'Languages available' ); ?></th></tr>
						<tr>
							<td><?php transprint( 'Language' ); ?></td>
							<td><?php transprint( 'Moderator' ); ?></td>
							<td><?php transprint( 'Status' ); ?></td>
							<td><?php transprint( 'Contributors' ); ?></td>
							<td align="right"><?php transprint( 'Users' ); ?></td>
						</tr>
<?php
$query = "SELECT * " .
		"FROM languages " .
		"ORDER BY default_language DESC, language ASC";
$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
$num = mysql_numrows( $result );
$i = 0;
while( $i < $num ) {
	if( $i % 2 == 0 ) {
		$even = ' class="even"';
	}
	else {
		$even = '';
	}
	
	if( mysql_result( $result, $i, 'user_id' ) != -1 ) {
		$query2 = "SELECT username " .
				"FROM users " .
				"WHERE user_id = " . mysql_result( $result, $i, 'user_id' );
		$result2 = mysql_query( $query2 ) or die( "Query failed : " . mysql_error() );
		$row2 = mysql_fetch_array( $result2, MYSQL_ASSOC );
		$moderator = $row2[ 'username' ];
	}
	else {
		$moderator = '-';
	}
	
	
	if( mysql_result( $result, $i, "default_language" ) == 1 ) {
    	$status = translate( 'default language' );
	}
	else {
		$language_info = Array();
		$query2 = "SELECT count(*) " .
				"FROM translations " .
				"WHERE language = '" . mysql_result( $result, $i, 'language' ) . "' AND approved = 1";
		$result2 = mysql_query( $query2 ) or die( "Query failed : " . mysql_error() );
		$row2 = mysql_fetch_array( $result2, MYSQL_ASSOC );
		$language_info[ 'approved' ] = $row2[ 'count(*)' ];
		
		$query2 = "SELECT count(*) " .
				"FROM translations " .
				"WHERE language = '" . mysql_result( $result, $i, 'language' ) . "' AND translated = 1 AND approved = 0";
		$result2 = mysql_query( $query2 ) or die( "Query failed : " . mysql_error() );
		$row2 = mysql_fetch_array( $result2, MYSQL_ASSOC );
		$language_info[ 'pending' ] = $row2[ 'count(*)' ];
		$query2 = "SELECT count(*) " .
				"FROM translations " .
				"WHERE language = '" . mysql_result( $result, $i, 'language' ) . "' AND translated = 0";
		$result2 = mysql_query( $query2 ) or die( "Query failed : " . mysql_error() );
		$row2 = mysql_fetch_array( $result2, MYSQL_ASSOC );
		$language_info[ 'untranslated' ] = $row2[ 'count(*)' ];
		$language_info[ 'translated' ] = $language_info[ 'pending' ] + $language_info[ 'approved' ];
		
		$status = translate( 'Translated and approved' ) . ": " . number_format( $language_info[ 'approved' ] ) . "<br />" .
				translate( 'Awaiting approval' ) . ": " . number_format( $language_info[ 'pending' ] ) . "<br />" .
				translate( 'Not translated yet' ) . ": " . number_format( $language_info[ 'untranslated' ] );
	}
?>
						<tr<?php print( $even ); ?>>
							<td><?php print( mysql_result( $result, $i, "title" ) . " (" . mysql_result( $result, $i, "language" ) ); ?>)</td>
							<td><?php print( $moderator ); ?></td>
							<td><?php print( $status ); ?></td>
							<td>
<?php 
	if( mysql_result( $result, $i, "default_language" ) == 1 ) {
		print( "-" );
	}
	else {
?>
								<ul>
<?php	
		$query2 = "SELECT user_id " .
				"FROM translations " .
				"WHERE language = '" . mysql_result( $result, $i, "language" ) . "' AND user_id != -1 " .
				"GROUP BY user_id ";
				/*"ORDER BY " .
					"( SELECT count(*) " .
					"FROM translations AS translations2 " .
					"WHERE translations2.approved = 1 AND translations2.user_id = translations.user_id AND translations2.language = '" . mysql_result( $result, $i, "language" ) . "' ) DESC";*/
		//print( "query: $query2<br />" );
		$result2 = mysql_query( $query2 ) or die( "Query failed : " . mysql_error() );
		$num2 = mysql_numrows( $result2 );
		$i2 = 0;
		if( $num2 > 0 ) {
			while( $i2 < $num2 ) {
				$query3 = "SELECT username " .
						"FROM users " .
						"WHERE user_id = " . mysql_result( $result2, $i2, "user_id" );
				$result3 = mysql_query( $query3 ) or die( "Query failed : " . mysql_error() );
				$row3 = mysql_fetch_array( $result3, MYSQL_ASSOC );
				$text = $row3[ 'username' ];
				
				/*$add = '';
				$query3 = "SELECT count(translation_id) " .
						"FROM translations " .
						"WHERE language = '" . mysql_result( $result, $i, 'language' ) . "' AND translated = 1 AND approved = 1 AND user_id = " . mysql_result( $result2, $i2, "user_id" );
				$result3 = mysql_query( $query3 ) or die( "Query failed : " . mysql_error() );
				$row3 = mysql_fetch_array( $result3, MYSQL_ASSOC );
				if( $row3[ 'count(translation_id)' ] > 0 ) {
					$add = translate( 'Approved' ) . ': ' . number_format( $row3[ 'count(translation_id)' ] );
				}
				$query3 = "SELECT count(translation_id) " .
						"FROM translations " .
						"WHERE language = '" . mysql_result( $result, $i, 'language' ) . "' AND translated = 1 AND approved = 0 AND user_id = " . mysql_result( $result2, $i2, "user_id" );
				$result3 = mysql_query( $query3 ) or die( "Query failed : " . mysql_error() );
				$row3 = mysql_fetch_array( $result3, MYSQL_ASSOC );
				if( $row3[ 'count(translation_id)' ] > 0 ) {
					if( $add != '' ) {
						$add .= ', '; 
					}
					$add .= translate( 'Awaiting approval' ) . ': ' . number_format( $row3[ 'count(translation_id)' ] );
				}
				$text .= ' (' . $add . ')';*/
?>
									<li><?php print( $text ); ?></li>
<?php		
				$i2 ++;
			}
		}
		else {
			transprint( 'None' );
		}
?>
								</ul>
<?php
	} 
?>
							</td>
							<td align="right">
<?php
	$query2 = "SELECT count(user_id) " .
			"FROM users " .
			"WHERE language = '" . mysql_result( $result, $i, 'language' ) . "'";
	$result2 = mysql_query( $query2 ) or die( "Query failed : " . mysql_error() );
	$row2 = mysql_fetch_array( $result2, MYSQL_ASSOC );
	print( number_format( $row2[ 'count(user_id)' ] ) );
?>
							</td>
						</tr>		
<?php	
    $i ++;
}
?>
					</table>
					<br />
					<div class="blok">
						<strong><?php transprint( 'More information' ); ?></strong><br />
						<?php transprint( 'If your language is missing from this list and you would like to help translate the game into your language <a href="../diplomacy/send_letter.php?to=Zworf">send a letter to Zworf</a> applying for language moderator for your language.' ); ?><br />
						<br />
						<?php transprint( 'Keep in mind all languages except the default language are community maintained and might not be a full translation of the game yet.' ); ?><br />
						<?php transprint( 'To help translate the game into a certain language, go to account settings and select the language.' ); ?><br />
						<?php transprint( 'A translate link will be added on your overview page, from where you can see the languages progress and help translate.' ); ?>
					</div>
<?php
aos_footer();
?>
